#!/usr/bin/env node 
const path = require('path')
const fs = require('fs')
const {INFO,ERROR} = require('../src/commonLib')
const {compileClsp,compileJs} = require('../index');


//当前目录
const cwdPath = process.cwd();

//预编译文件
const arg = process.argv[2]


if(!arg){
	INFO("Please enter the file you want to compile");
	INFO("Example preclsp x.preclsp");
	return;
}

//location the file
let targetFile = arg.indexOf("/") == 0 ? arg : path.join(cwdPath,arg)

// if(!fs.existsSync(targetFile)){
// 	targetFile = path.join(cwdPath,arg);
// }

if(!fs.existsSync(targetFile)){
	ERROR(` file not exist! \n Please check file path:${targetFile}`);
	return
}

switch(path.extname(targetFile)){
	case ".clsp": compileClsp(targetFile);break;
	case ".js": compileJs(targetFile);break;
	default:"ERROR just compile clsp or js file" 
}
